#include "com_voe_VoEVolumeControl.h"
#include "voe_volume_control.h"
#include "jni_api.h"
#include "OutputParam.h"

/*
 * Class:     com_voe_VoEVolumeControl
 * Method:    GetInterface
 * Signature: (J)J
 */
JNIEXPORT jlong JNICALL Java_com_voe_VoEVolumeControl_GetInterface
  (JNIEnv * env, jclass cls, jlong p_voiceEngine)
{
	return (jlong)webrtc::VoEVolumeControl::GetInterface((webrtc::VoiceEngine*)p_voiceEngine);
}

/*
 * Class:     com_voe_VoEVolumeControl
 * Method:    Release
 * Signature: (J)I
 */
JNIEXPORT jint JNICALL Java_com_voe_VoEVolumeControl_Release
  (JNIEnv * env, jclass cls, jlong p)
{
	webrtc::VoEVolumeControl* pVoEVolumeControl = (webrtc::VoEVolumeControl*)p;
	return pVoEVolumeControl->Release();
}

/*
 * Class:     com_voe_VoEVolumeControl
 * Method:    SetSpeakerVolume
 * Signature: (JI)I
 */
JNIEXPORT jint JNICALL Java_com_voe_VoEVolumeControl_SetSpeakerVolume
  (JNIEnv * env, jclass cls, jlong p, jint volume)
{
	webrtc::VoEVolumeControl* pVoEVolumeControl = (webrtc::VoEVolumeControl*)p;
	return pVoEVolumeControl->SetSpeakerVolume(volume);
}

/*
 * Class:     com_voe_VoEVolumeControl
 * Method:    GetSpeakerVolume
 * Signature: (JLcom/voe/common/OutputParam;)I
 */
JNIEXPORT jint JNICALL Java_com_voe_VoEVolumeControl_GetSpeakerVolume
  (JNIEnv * env, jclass cls, jlong p, jobject obj)
{
	webrtc::VoEVolumeControl* pVoEVolumeControl = (webrtc::VoEVolumeControl*)p;
	unsigned int volume = 0;
	jint result = pVoEVolumeControl->GetSpeakerVolume(volume);
	if(result == 0)
	{
		JniOutputBuilder job(env);
		OutputParam param(env, obj);
		param.setArray(job.add((int)volume).getOutput());
	}
	return result;
}

/*
 * Class:     com_voe_VoEVolumeControl
 * Method:    SetSystemOutputMute
 * Signature: (JZ)I
 */
JNIEXPORT jint JNICALL Java_com_voe_VoEVolumeControl_SetSystemOutputMute
	(JNIEnv * env, jclass cls, jlong p, jboolean enable)
{
	webrtc::VoEVolumeControl* pVoEVolumeControl = (webrtc::VoEVolumeControl*)p;
	return pVoEVolumeControl->SetSystemOutputMute(enable != 0);
}

/*
 * Class:     com_voe_VoEVolumeControl
 * Method:    GetSystemOutputMute
 * Signature: (JLcom/voe/common/OutputParam;)I
 */
JNIEXPORT jint JNICALL Java_com_voe_VoEVolumeControl_GetSystemOutputMute
  (JNIEnv * env, jclass cls, jlong p, jobject obj)
{
	webrtc::VoEVolumeControl* pVoEVolumeControl = (webrtc::VoEVolumeControl*)p;
	bool enabled = false;
	jint result = pVoEVolumeControl->GetSystemOutputMute(enabled);
	if(result == 0)
	{
		JniOutputBuilder job(env);
		OutputParam param(env, obj);
		param.setArray(job.add(enabled).getOutput());
	}
	return result;
}

/*
 * Class:     com_voe_VoEVolumeControl
 * Method:    SetMicVolume
 * Signature: (JI)I
 */
JNIEXPORT jint JNICALL Java_com_voe_VoEVolumeControl_SetMicVolume
	(JNIEnv * env, jclass cls, jlong p, jint volume)
{
	webrtc::VoEVolumeControl* pVoEVolumeControl = (webrtc::VoEVolumeControl*)p;
	return pVoEVolumeControl->SetMicVolume(volume);
}

/*
 * Class:     com_voe_VoEVolumeControl
 * Method:    GetMicVolume
 * Signature: (JLcom/voe/common/OutputParam;)I
 */
JNIEXPORT jint JNICALL Java_com_voe_VoEVolumeControl_GetMicVolume
  (JNIEnv * env, jclass cls, jlong p, jobject obj)
{
	webrtc::VoEVolumeControl* pVoEVolumeControl = (webrtc::VoEVolumeControl*)p;
	unsigned int volume = 0;
	jint result = pVoEVolumeControl->GetMicVolume(volume);
	if(result == 0)
	{
		JniOutputBuilder job(env);
		OutputParam param(env, obj);
		param.setArray(job.add((int)volume).getOutput());
	}
	return result;
}

/*
 * Class:     com_voe_VoEVolumeControl
 * Method:    SetInputMute
 * Signature: (JIZ)I
 */
JNIEXPORT jint JNICALL Java_com_voe_VoEVolumeControl_SetInputMute
	(JNIEnv * env, jclass cls, jlong p, jint channel, jboolean enable)
{
	webrtc::VoEVolumeControl* pVoEVolumeControl = (webrtc::VoEVolumeControl*)p;
	return pVoEVolumeControl->SetInputMute(channel, enable != 0);
}

/*
 * Class:     com_voe_VoEVolumeControl
 * Method:    GetInputMute
 * Signature: (JILcom/voe/common/OutputParam;)I
 */
JNIEXPORT jint JNICALL Java_com_voe_VoEVolumeControl_GetInputMute
  (JNIEnv * env, jclass cls, jlong p, jint channel, jobject obj)
{
	webrtc::VoEVolumeControl* pVoEVolumeControl = (webrtc::VoEVolumeControl*)p;
	bool enabled = false;
	jint result = pVoEVolumeControl->GetInputMute(channel, enabled);
	if(result == 0)
	{
		JniOutputBuilder job(env);
		OutputParam param(env, obj);
		param.setArray(job.add(enabled).getOutput());
	}
	return result;
}

/*
 * Class:     com_voe_VoEVolumeControl
 * Method:    SetSystemInputMute
 * Signature: (JZ)I
 */
JNIEXPORT jint JNICALL Java_com_voe_VoEVolumeControl_SetSystemInputMute
	(JNIEnv * env, jclass cls, jlong p, jboolean enable)
{
	webrtc::VoEVolumeControl* pVoEVolumeControl = (webrtc::VoEVolumeControl*)p;
	return pVoEVolumeControl->SetSystemInputMute(enable != 0);
}

/*
 * Class:     com_voe_VoEVolumeControl
 * Method:    GetSystemInputMute
 * Signature: (JLcom/voe/common/OutputParam;)I
 */
JNIEXPORT jint JNICALL Java_com_voe_VoEVolumeControl_GetSystemInputMute
  (JNIEnv * env, jclass cls, jlong p, jobject obj)
{
	webrtc::VoEVolumeControl* pVoEVolumeControl = (webrtc::VoEVolumeControl*)p;
	bool enabled = false;
	jint result = pVoEVolumeControl->GetSystemInputMute(enabled);
	if(result == 0)
	{
		JniOutputBuilder job(env);
		OutputParam param(env, obj);
		param.setArray(job.add(enabled).getOutput());
	}
	return result;
}

/*
 * Class:     com_voe_VoEVolumeControl
 * Method:    GetSpeechInputLevel
 * Signature: (JLcom/voe/common/OutputParam;)I
 */
JNIEXPORT jint JNICALL Java_com_voe_VoEVolumeControl_GetSpeechInputLevel
  (JNIEnv * env, jclass cls, jlong p, jobject obj)
{
	webrtc::VoEVolumeControl* pVoEVolumeControl = (webrtc::VoEVolumeControl*)p;
	unsigned int level = 0;
	jint result = pVoEVolumeControl->GetSpeechInputLevel(level);
	if(result == 0)
	{
		JniOutputBuilder job(env);
		OutputParam param(env, obj);
		param.setArray(job.add((int)level).getOutput());
	}
	return result;
}

/*
 * Class:     com_voe_VoEVolumeControl
 * Method:    GetSpeechOutputLevel
 * Signature: (JILcom/voe/common/OutputParam;)I
 */
JNIEXPORT jint JNICALL Java_com_voe_VoEVolumeControl_GetSpeechOutputLevel
	(JNIEnv * env, jclass cls, jlong p, jint channel, jobject obj)
{
	webrtc::VoEVolumeControl* pVoEVolumeControl = (webrtc::VoEVolumeControl*)p;
	unsigned int level = 0;
	jint result = pVoEVolumeControl->GetSpeechOutputLevel(channel, level);
	if(result == 0)
	{
		JniOutputBuilder job(env);
		OutputParam param(env, obj);
		param.setArray(job.add((int)level).getOutput());
	}
	return result;
}

/*
 * Class:     com_voe_VoEVolumeControl
 * Method:    GetSpeechInputLevelFullRange
 * Signature: (JLcom/voe/common/OutputParam;)I
 */
JNIEXPORT jint JNICALL Java_com_voe_VoEVolumeControl_GetSpeechInputLevelFullRange
	(JNIEnv * env, jclass cls, jlong p, jobject obj)
{
	webrtc::VoEVolumeControl* pVoEVolumeControl = (webrtc::VoEVolumeControl*)p;
	unsigned int level = 0;
	jint result = pVoEVolumeControl->GetSpeechInputLevelFullRange(level);
	if(result == 0)
	{
		JniOutputBuilder job(env);
		OutputParam param(env, obj);
		param.setArray(job.add((int)level).getOutput());
	}
	return result;
}

/*
 * Class:     com_voe_VoEVolumeControl
 * Method:    GetSpeechOutputLevelFullRange
 * Signature: (JILcom/voe/common/OutputParam;)I
 */
JNIEXPORT jint JNICALL Java_com_voe_VoEVolumeControl_GetSpeechOutputLevelFullRange
  (JNIEnv * env, jclass cls, jlong p, jint channel, jobject obj)
{
	webrtc::VoEVolumeControl* pVoEVolumeControl = (webrtc::VoEVolumeControl*)p;
	unsigned int level = 0;
	jint result = pVoEVolumeControl->GetSpeechOutputLevelFullRange(channel, level);
	if(result == 0)
	{
		JniOutputBuilder job(env);
		OutputParam param(env, obj);
		param.setArray(job.add((int)level).getOutput());
	}
	return result;
}

/*
 * Class:     com_voe_VoEVolumeControl
 * Method:    SetChannelOutputVolumeScaling
 * Signature: (JIF)I
 */
JNIEXPORT jint JNICALL Java_com_voe_VoEVolumeControl_SetChannelOutputVolumeScaling
	(JNIEnv * env, jclass cls, jlong p, jint channel, jfloat scaling)
{
	webrtc::VoEVolumeControl* pVoEVolumeControl = (webrtc::VoEVolumeControl*)p;
	return pVoEVolumeControl->SetChannelOutputVolumeScaling(channel, scaling);
}

/*
 * Class:     com_voe_VoEVolumeControl
 * Method:    GetChannelOutputVolumeScaling
 * Signature: (JILcom/voe/common/OutputParam;)I
 */
JNIEXPORT jint JNICALL Java_com_voe_VoEVolumeControl_GetChannelOutputVolumeScaling
  (JNIEnv * env, jclass cls, jlong p, jint channel, jobject obj)
{
	webrtc::VoEVolumeControl* pVoEVolumeControl = (webrtc::VoEVolumeControl*)p;
	float scaling = 0;
	jint result = pVoEVolumeControl->GetChannelOutputVolumeScaling(channel, scaling);
	if(result == 0)
	{
		JniOutputBuilder job(env);
		OutputParam param(env, obj);
		param.setArray(job.add(scaling).getOutput());
	}
	return result;
}

/*
 * Class:     com_voe_VoEVolumeControl
 * Method:    SetOutputVolumePan
 * Signature: (JIFF)I
 */
JNIEXPORT jint JNICALL Java_com_voe_VoEVolumeControl_SetOutputVolumePan
	(JNIEnv * env, jclass cls, jlong p, jint channel, jfloat left, jfloat right)
{
	webrtc::VoEVolumeControl* pVoEVolumeControl = (webrtc::VoEVolumeControl*)p;
	return pVoEVolumeControl->SetOutputVolumePan(channel, left, right);
}

/*
 * Class:     com_voe_VoEVolumeControl
 * Method:    GetOutputVolumePan
 * Signature: (JILcom/voe/common/OutputParam;)I
 */
JNIEXPORT jint JNICALL Java_com_voe_VoEVolumeControl_GetOutputVolumePan
  (JNIEnv * env, jclass cls, jlong p, jint channel, jobject obj)
{
	webrtc::VoEVolumeControl* pVoEVolumeControl = (webrtc::VoEVolumeControl*)p;
	float left, right;
	jint result = pVoEVolumeControl->GetOutputVolumePan(channel, left, right);
	if(result == 0)
	{
		JniOutputBuilder job(env);
		OutputParam param(env, obj);
		param.setArray(job.add(left).add(right).getOutput());
	}
	return result;
}
